package org.abc.fund.repository.funds;

import org.abc.fund.entity.funds.FundMtss;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Optional;

/**
 * Repository for FundMtss entity.
 */
@Repository
public interface FundMtssRepository extends JpaRepository<FundMtss, Long> {
    /**
     * 根据基金代码和日期查找融资融券记录
     */
    Optional<FundMtss> findByFundCodeAndDate(String fundCode, LocalDate date);
    
    /**
     * 根据基金代码查找最新的融资融券记录（按日期降序）
     */
    Optional<FundMtss> findTopByFundCodeOrderByDateDesc(String fundCode);

    @Modifying
    @Transactional
    void deleteByFundCodeAndDateBetween(String fundCode, LocalDate startDate, LocalDate endDate);
}

